/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
 *
 */

import { TrackAPI } from '@ohos/hvigor';

import { ProjectBuildProfile } from '../../options/build/project-build-profile.js';
import { Product } from '../../plugin/context/plugin-context.js';
import ProductBuildOpt = ProjectBuildProfile.ProductBuildOpt;
import { ProjectModel } from '../../model/project/project-model.js';

export class CoreProduct implements Product {
  private productBuildOpt: ProductBuildOpt;
  private productName: string | undefined;
  private bundleName: string | undefined;
  private bundleType: string | undefined;
  private projectModel: ProjectModel | undefined;

  constructor(productBuildOpt: ProductBuildOpt, projectModel: ProjectModel) {
    this.productBuildOpt = productBuildOpt;
    this.projectModel = projectModel;
    this.transformToCoreProduct();
  }

  transformToCoreProduct(): void {
    this.productName = this.productBuildOpt.name;
    this.bundleName = this.productBuildOpt.bundleName ?? this.projectModel!.getDefaultBundleName();
    this.bundleType = this.productBuildOpt.bundleType ?? this.projectModel!.getBundleType();
  }

  @TrackAPI getBundleName(): string {
    return this.bundleName!;
  }

  @TrackAPI getBundleType(): string {
    return this.bundleType!;
  }

  @TrackAPI getProductName(): string {
    return this.productName!;
  }
}
